﻿// (c) Copyright slimCODE Software Inc. - www.slimcode.com
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using SlimCode.Windows.Controls.Mobile;
using System.Drawing;

namespace SlimCode.SlimPasswords
{
  class PasswordView : ItemView
  {
    public PasswordView( PasswordItem item )
      : base( item.Name, 2 )
    {
      this.Item = item;
    }

    public PasswordItem Item { get; private set; }

    protected override void DrawTopLayer( TemplatedPaintEventArgs e )
    {
      Rectangle rect = this.ClientRectangle;

      rect.Inflate( -5, -2 );
      rect.Height /= 2;

      e.StringFormat.Alignment = StringAlignment.Near;
      e.StringFormat.LineAlignment = StringAlignment.Far;

      e.Graphics.DrawString( 
        this.Text, 
        e.BoldFont, 
        e.ForegroundBrush, 
        rect,
        e.StringFormat );

      rect.Y += rect.Height;
      e.StringFormat.LineAlignment = StringAlignment.Near;
      e.StringFormat.FormatFlags = StringFormatFlags.NoWrap;

      e.Graphics.DrawString(
        string.Format( "{0}, {1}",
          string.IsNullOrEmpty( this.Item.UserName ) ? "(no username)" : this.Item.UserName,
          string.IsNullOrEmpty( this.Item.Email ) ? "(no email)" : this.Item.Email ),
        e.SmallFont,
        e.ForegroundBrush,
        rect,
        e.StringFormat );
    }
  }
}
